//封装了一个题目对象
export const Question = function(qIndex, id,subQuesId, majorIds, majorNames, subjectIds, subjectNames, questionType,
	questionTypeName, classify, questionStem,questionTitle, options, answer, analysis, complex, kwptIds, kwptNames, 
	tagIds, tagNames, chapterId, chapterName,sectionId, sectionName, score, isReal, isIntoLib, subQuestionLength,
	subQuestionList,userAnswer,userScore,isDone,result,scoreKeys,comment,userAnswerAttachs) {
	this.qIndex = qIndex;//题目索引
	this.id = id;//题目id
	this.queId = id;//题目id
	this.subQuesId = subQuesId;//子题ID
	this.majorIds = majorIds;//所属类别id
	this.majorNames = majorNames;//所属类别名称
	this.subjectIds = subjectIds;//所属科目id
	this.subjectNames = subjectNames;//所属科目名称
	this.questionType = questionType;//题目类型
	this.questionTypeName = questionTypeName;//题目类型名称
	this.classify = classify;//面试题属性 只有是面试题才有效 
	this.questionStem = questionStem;//题干 材料题
	this.questionTitle = questionTitle;//题目
	this.options = options ? JSON.parse(options) : "";//选项
	this.answer = answer;//用户答案
	this.analysis = analysis;//解析
	this.complex = complex;//难易程度
	this.kwptIds = kwptIds;//所属知识点id集合
	this.kwptNames = kwptNames;//所属知识点名称集合
	this.tagIds = tagIds;//所属标签id集合
	this.tagNames = tagNames;//所属标签名称集合
	this.chapterId = chapterId || "";//章id
	this.chapterName = chapterName || "";//章名称
	this.sectionId = sectionId || "";//节id
	this.sectionName = sectionName || "";//节名称
	this.score = score;//题目分数
	this.isReal = isReal;//是否是真题
	this.isIntoLib = isIntoLib;//是否
	this.subQuestionLength = subQuestionLength || 0;//子题数量 为-1表示是前面题目的兄弟题目
	this.subQuestionList = subQuestionList;//子题集合（非扁平结构）
	this.userAnswer = userAnswer;//用户答案
	this.userScore = userScore;//用户得分
	this.isDone = isDone;//是否完成
	this.result = result;//是否正确
	this.scoreKeys = scoreKeys ? JSON.parse(scoreKeys) : "";//材料题的得分点
	this.comment = comment;
	this.userAnswerAttachs = userAnswerAttachs?JSON.parse(userAnswerAttachs) : "";
}

//转成扁平化数据 材料题父题没有了，只有子题（子题包含了父题信息，并且按照题目顺序 和 subQuestionLength 进行关联 
//子题第一题的 subQuestionLength 为大题一共有多少子题 其余题目的subQuestionLength 为 -1 表示是前面题目的兄弟题目）
export const transQuestionData = (list, currentPage, numPerPage) => {
	let dataList = [];
	if (list && list.length > 0) {
		list.forEach((el, index) => {
			let qIndex = (currentPage - 1) * numPerPage + index + 1;
			if (el.type == 7) {
				if (el.cens.length > 0) {
					for (let i = 0; i < el.cens.length; i++) {
						let subQ = new Question(qIndex, el.id,el.cens[i].id, el.majorIds, el.majorNames, el.subjectIds, el.subjectNames, el.type,
							el.typeName + ":" + el.cens[i].typeName, el.classify, el.material, el.cens[i].title, el.cens[i].attach, el.cens[i].solution,
							el.cens[i].resolution, el.cens[i].complex, el.kwptIds, el.kwptNames, el.tagIds, el.tagNames, el.chapterId,
							el.chapterName, el.sectionId, el.sectionName, el.cens[i].score, el.isReal, el.isIntoLib);
						if (i == 0) {
							subQ.subQuestionLength = el.cens.length;
						} else {
							subQ.subQuestionLength = -1;
						}
						dataList.push(subQ);

					}
				}
			} else {
				let q = new Question(qIndex, el.id,el.cens[0].id, el.majorIds, el.majorNames, el.subjectIds, el.subjectNames, el.type, el.typeName,
					el.classify,"", el.cens[0].title, el.cens[0].attach, el.cens[0].solution, el.cens[0].resolution, el.cens[0].complex, el.kwptIds,
					el.kwptNames,el.tagIds, el.tagNames, el.chapterId, el.chapterName, el.sectionId, el.sectionName, el.cens[0].score, el.isReal,
					el.isIntoLib,0);
				dataList.push(q);
			}

		})
		return dataList;
	}
}

//非扁平化的 材料题包含了子题
export const transQuestion = (list, currentPage, numPerPage) =>{
	let idList = [];
	let dataList = [];
	if (list && list.length > 0) {
		list.forEach((el, index) => {
			let qIndex = (currentPage - 1) * numPerPage + index + 1;
			idList.push(el.id);
			if (el.type == 7) {
				let userScore = 0;
				let isDone;
				if(el.ansResult){
					userScore = el.ansResult.markScore;
					isDone =el.ansResult.isDone;
				}
				let q = new Question(qIndex, el.id, null, el.majorIds, el.majorNames, el.subjectIds, el.subjectNames, el.type, el.typeName,
					el.classify,el.material, "", "","", "", "", el.kwptIds, el.kwptNames,el.tagIds, el.tagNames, el.chapterId, el.chapterName, 
					el.sectionId, el.sectionName, el.score, el.isReal,el.isIntoLib,el.cens.length,[],"",userScore,isDone);
				let subList = [];
				if (el.cens.length > 0) {
					for (let i = 0; i < el.cens.length; i++) {
						let userAnswer,userScore,isDone,result,reviews,answersAttachs;
						let ansResult = el.cens[i].ansResult;
						if(ansResult){
							userAnswer = ansResult.answers;
							userScore = ansResult.markScore;
							isDone = ansResult.isDone;
							result = ansResult.markRight;
							reviews = ansResult.reviews;
							answersAttachs = ansResult.answersAttachs;
						};
						let subQ = new Question(i+1,el.id, el.cens[i].id, el.majorIds, el.majorNames, el.subjectIds, el.subjectNames, el.cens[i].type,
							el.typeName + ":" + el.cens[i].typeName, el.classify, el.material, el.cens[i].title, el.cens[i].attach, el.cens[i].solution,
							el.cens[i].resolution, el.cens[i].complex, el.kwptIds, el.kwptNames, el.tagIds, el.tagNames, el.chapterId,el.chapterName, 
							el.sectionId, el.sectionName, el.cens[i].score, el.isReal, el.isIntoLib,null,[],userAnswer,userScore,isDone,result,el.cens[i].scoreKeys,
							reviews,answersAttachs);
						if (i == 0) {
							subQ.subQuestionLength = el.cens.length;
						} else {
							subQ.subQuestionLength = -1;
						}
						subList.push(subQ);
	
					}
				}
				q.subQuestionList = subList;
				dataList.push(q);
			} else {
				let userAnswer,userScore,isDone,result,reviews,answersAttachs;
				let ansResult = el.cens[0].ansResult;
				if(ansResult){
					userAnswer = ansResult.answers;
					userScore = ansResult.markScore;
					isDone = ansResult.isDone;
					result = ansResult.markRight;
					reviews = ansResult.reviews;
					answersAttachs = ansResult.answersAttachs;
				};
				let q = new Question(qIndex, el.id,el.cens[0].id,el.majorIds, el.majorNames, el.subjectIds, el.subjectNames, el.type, el.typeName,
					el.classify,"", el.cens[0].title, el.cens[0].attach, el.cens[0].solution, el.cens[0].resolution, el.cens[0].complex, el.kwptIds,
					el.kwptNames,el.tagIds, el.tagNames, el.chapterId, el.chapterName, el.sectionId, el.sectionName, el.cens[0].score, el.isReal,
					el.isIntoLib,0,[],userAnswer,userScore,isDone,result,el.cens[0].scoreKeys,reviews,answersAttachs);
				dataList.push(q);
			}
	
		});
	}
	return {dataList:dataList,idList:idList};
}
export const classifyList = [{
	id: 2,
	name: "结构化"
}, {
	id: 3,
	name: "备课"
}];
export const classifyMap = {
	2: "结构化",
	3: "备课"
}; //和数组对应
export const typeList = [{
	id: 2,
	name: "单选题"
}, {
	id: 4,
	name: "问答题"
}, {
	id: 7,
	name: "材料题"
}];
export const typeMap = {
	2:"单选题",
	4:"问答题",
	7:"材料题"
}
export const complexList = ["简单", "一般", "中等", "困难", "很难"];
export const character = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
export const getTotalScore = (questionList) =>{
	let score = 0;
	if(questionList){
		questionList.forEach(el=>{
			score += Number(el.score);
		})
	}
	return score;
}